package com.heima.behavior.controller;

import com.heima.behavior.Service.BehaviorService;
import com.heima.behavior.dto.*;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@RequestMapping("/api/v1")
public class BehaviorController {

    @Autowired
    private BehaviorService behaviorService;

    /**
     * 保存关注行为
     * @param dto
     * @return
     */
    @PostMapping(path = "/follow_behavior/user_follow")
    @ApiOperation("保存关注行为")
    public ResponseResult saveFollow(@RequestBody FollowBehaviorDto dto){
        behaviorService.saveFollow(dto);
        return ResponseResult.success();
    }

    /**
     * 保存点赞行为
     * @param dto
     * @return
     */
    @PostMapping(path = "/likes_behavior")
    @ApiOperation("保存点赞行为")
    public ResponseResult saveLikes(@RequestBody LikesBehaviorDto dto){
        behaviorService.saveLikes(dto);
        return ResponseResult.success();
    }

    /**
     * 阅读行为
     * @param dto
     * @return
     */
    @PostMapping(path = "/read_behavior")
    @ApiOperation("阅读行为")
    public ResponseResult saveRead(@RequestBody ReadBehaviorDto dto){
        behaviorService.saveRead(dto);
        return ResponseResult.success();
    }

    /**
     * 保存不喜欢行为
     * @param dto
     * @return
     */
    @PostMapping(path = "/un_likes_behavior")
    @ApiOperation("保存不喜欢行为")
    public ResponseResult saveUnLikes(@RequestBody UnLikesBehaviorDto dto){
        behaviorService.saveUnLikes(dto);
        return ResponseResult.success();
    }

    /**
     * 保存收藏行为
     * @param dto
     * @return
     */
    @PostMapping(path = "/collection_behavior")
    @ApiOperation("保存收藏行为")
    public ResponseResult saveCollection(@RequestBody CollectionBehaviorDto dto){
        behaviorService.saveCollection(dto);
        return ResponseResult.success();
    }

    /**
     * 状态回显
     * @param dto
     * @return
     */
    @PostMapping(path = "/behavior/load_article_behavior")
    @ApiOperation("保存收藏行为")
    public ResponseResult loadArticleBehavior(@RequestBody ArticleBehaviorDto dto){
        HashMap<String, Object> data = behaviorService.loadArticleBehavior(dto);
        return ResponseResult.success(data);
    }
}
